import u from "../utils";
import fetch from "../utils/fetch";
import {PAGE} from "../constants";
import {WeaLocaleProvider} from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;

const _api = u.api(PAGE);
const _fetch = fetch(PAGE);

export default {
  getComponents: () => _api('getComponents'),
  getDesign: appid => _api('design', { data: { appid } }),
  getPageComps: shortkey => _api('getPageComps', { data: { key: shortkey } }),
  getShortKey: appid => _api('getShortKey', { data: { appid }, ignoreError: true }),
  save: (appid, components, style) => _api('config', {
    type: 'post',
    data: { 
      appid, 
      components: JSON.stringify(components),
      style: JSON.stringify(style)
    },
    msg: getLabel('502231','保存成功') 
  }),
  getSetInfo: appid => _api('setting/info', { data: { appid }, ignoreError: true}),
  getSubmissionAuthority: () => _api('getSubmissionAuthority'),
  getFillinFrequency: () => _api('getFillinFrequency'),
  uploadImg: data => _fetch('uploadFile', {
    method: 'post',
    body: data
  }),
  setUpdate: data => _api('setting/update', {
    type: 'post',
    data: data,
  }),
  wxUpdate: data => _api('wxsetting/update', {
    type: 'post',
    data: data,
  }),
  getWxInfo: appid => _api('wxsetting/info', { data: { appid }}),
  getWxTypeInfo: () => u.api('settings')('info')  ,
  updateWxTypeInfo: data => u.api('settings')('update',{
    type: 'post',
    data: data,
  }),
  getPageRules: appid => _api('rules/info', { data: { appid } }),
  updatePageRules: (appid, rules) => _api('rules/config', { 
    type: 'post',
    data: { appid, rules },
    msg: getLabel('502231', '保存成功')
  }) 
}